<template>
  <div class="inventoryTransact">
    <div class="publicSearch">
      <div class="searchBar" :style="{ height: isMoreSearch ? 'auto' : '' }">
        <el-button-group>
          <el-button @click="getInventoryTransactData" size="mini" icon="el-icon-search">查询</el-button>
          <el-button @click="clearSearchData" size="mini" icon="el-icon-refresh">重置</el-button>
        </el-button-group>
        <div>
          <span>物料编码</span>
          <el-input v-model="searchData.itemCode" size="mini" placeholder="物料编码" clearable></el-input>
        </div>
        <div>
          <span>物料名称</span>
          <el-input v-model="searchData.itemName" size="mini" placeholder="物料名称" clearable></el-input>
        </div>
        <div>
          <span>事务类型</span>
          <el-select
            v-model="searchData.transactType"
            size="mini"
            filterable
            placeholder="请选择事务类型"
            clearable
          >
            <el-option
              v-for="item in transactTypes"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </div>
<!--        <div>-->
<!--          <span>单据类型</span>-->
<!--          <el-select-->
<!--            v-model="searchData.billType"-->
<!--            size="mini"-->
<!--            filterable-->
<!--            placeholder="请选择单据类型"-->
<!--            clearable-->
<!--          >-->
<!--            <el-option-->
<!--              v-for="item in billTypes"-->
<!--              :key="item.value"-->
<!--              :label="item.label"-->
<!--              :value="item.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </div>-->
        <div>
          <span>原因</span>
          <el-input v-model="searchData.reason" size="mini" placeholder="原因" clearable></el-input>
        </div>
        <div>
          <span>波次号</span>
          <el-input v-model="searchData.waveCode" size="mini" placeholder="波次号" clearable></el-input>
        </div>
        <div>
          <span>单据号</span>
          <el-input v-model="searchData.billNo" size="mini" placeholder="单据号" clearable></el-input>
        </div>
        <div>
          <span>状态</span>
          <el-select
            v-model="searchData.state"
            size="mini"
            filterable
            placeholder="请选择状态"
            clearable
          >
            <el-option :key="1" label="完成" :value="1"></el-option>
            <el-option :key="-1" label="撤回" :value="-1"></el-option>
          </el-select>
        </div>
        <div>
          <span>创建时间</span>
          <el-date-picker
            v-model="searchData.createTimeArr"
            size="mini"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </div>
        <div>
          <span>来自批次名称</span>
          <el-input v-model="searchData.fromBatchName" size="mini" placeholder="来自批次名称" clearable></el-input>
        </div>
        <div>
          <span>来自追踪号</span>
          <el-input v-model="searchData.fromBoxCode" size="mini" placeholder="来自追踪号" clearable></el-input>
        </div>
        <div>
          <span>来自货位编码</span>
          <el-input v-model="searchData.fromCellCode" size="mini" placeholder="来自货位编码" clearable></el-input>
        </div>

        <div>
          <span>调入批次名称</span>
          <el-input v-model="searchData.toBatchName" size="mini" placeholder="调入批次名称" clearable></el-input>
        </div>
        <div>
          <span>调入追踪号</span>
          <el-input v-model="searchData.toBoxCode" size="mini" placeholder="调入追踪号" clearable></el-input>
        </div>
        <div>
          <span>调入货位编码</span>
          <el-input v-model="searchData.toCellCode" size="mini" placeholder="调入货位编码" clearable></el-input>
        </div>

        <div>
          <span>创建人</span>
          <el-input v-model="searchData.createUserName" size="mini" placeholder="创建人" clearable></el-input>
        </div>
      </div>
      <span
        class="moreSearchBtn"
        :class="isMoreSearch ? 'el-icon-caret-top' : 'el-icon-caret-bottom'"
        @click="isMoreSearch = !isMoreSearch"
      ></span>
    </div>

    <div class="tableBox">
      <el-table-column fixed="left" type="index" width="50"></el-table-column>

      <el-table border highlight-current-row :data="inventoryTransacts" style="width: 100%">
        <el-table-column sortable prop="transactType" label="事务类型" align="center">
          <template slot-scope="scope">
            <span
              v-for="(item, index) in transactTypes"
              :key="index"
              v-if="scope.row.transactType === item.value"
            >{{ item.label }}</span>
          </template>
        </el-table-column>

        <el-table-column sortable show-overflow-tooltip prop="itemCode" label="物料编码" width="150">
          <template slot-scope="scope">
            <span
              class="textBtn"
              @click="
                $EventBus.$emit('showPublicModal', scope.row.itemCode, 'item')
              "
            >{{ scope.row.itemCode }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="itemName" label="物料名称" align="center">
          <template slot-scope="scope">
            <span
              class="textBtn"
              @click="
                $EventBus.$emit('showPublicModal', scope.row.itemCode, 'item')
              "
            >{{ scope.row.itemName }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="wareName" label="仓库" align="center">
          <template slot-scope="scope">
            <span
              class="textBtn"
              @click="
                $EventBus.$emit('showPublicModal', scope.row.wareId, 'ware')
              "
            >{{ scope.row.wareName }}</span>
          </template>
        </el-table-column>
        <!--        <el-table-column-->
        <!--          sortable-->
        <!--          show-overflow-tooltip-->
        <!--          prop="fromOrganizationName"-->
        <!--          label="货主"-->
        <!--          align="center"-->
        <!--        >-->
        <!--          <template slot-scope="scope">-->
        <!--            <span-->
        <!--              class="textBtn"-->
        <!--              @click="-->
        <!--                $EventBus.$emit(-->
        <!--                  'showPublicModal',-->
        <!--                  scope.row.fromOrganizationId,-->
        <!--                  'organization'-->
        <!--                )-->
        <!--              "-->
        <!--              >{{ scope.row.fromOrganizationName }}</span-->
        <!--            >-->
        <!--            <br />-->
        <!--            <span-->
        <!--              class="textBtn"-->
        <!--              @click="-->
        <!--                $EventBus.$emit(-->
        <!--                  'showPublicModal',-->
        <!--                  scope.row.toOrganizationId,-->
        <!--                  'organization'-->
        <!--                )-->
        <!--              "-->
        <!--              >{{ scope.row.toOrganizationName }}</span-->
        <!--            >-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="fromBatchName"
          label="批次"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.fromBatchName }}</span>
            <br />
            <span>{{ scope.row.toBatchName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="fromBoxCode"
          label="追踪号"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.fromBoxCode }}</span>
            <br />
            <span>{{ scope.row.toBoxCode }}</span>
          </template>
        </el-table-column>
        <!--        <el-table-column-->
        <!--          sortable-->
        <!--          show-overflow-tooltip-->
        <!--          prop="CellCode"-->
        <!--          label="货位编码"-->
        <!--          align="center"-->
        <!--        >-->
        <!--          <template slot-scope="scope">-->
        <!--            <span> {{ scope.row.fromCellCode }}</span>-->
        <!--            <br />-->
        <!--            <span> {{ scope.row.toCellCode }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
<!--        <el-table-column-->
<!--          sortable-->
<!--          show-overflow-tooltip-->
<!--          prop="fromPackDescribe"-->
<!--          label="单位"-->
<!--          align="center"-->
<!--        >-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ scope.row.fromPackDescribe }}</span>-->
<!--            <br />-->
<!--            <span>{{ scope.row.toPackDescribe }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="fromQuantity"
          label="主单位数量"
          width="120px"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.fromQuantity }}</span>
            <br />
            <span>{{ scope.row.toQuantity }}</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="createUserName"
          label="创建人"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              @click="
                $EventBus.$emit(
                  'showPublicModal',
                  scope.row.createUserId,
                  'account'
                )
              "
              type="text"
            >{{ scope.row.createUserName }}</el-button>
          </template>
        </el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="createTime"
          label="事务时间"
          align="center"
        >
          <template slot-scope="scope">{{ scope.row.createTime.substr(5, 11) }}</template>
        </el-table-column>

<!--        <el-table-column sortable prop="billType" label="单据类型" width="110">-->
<!--          <template slot-scope="scope">-->
<!--            <span-->
<!--              v-for="(item, index) in billTypes"-->
<!--              :key="index"-->
<!--              v-if="scope.row.billType === item.value"-->
<!--            >{{ item.label }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->

        <el-table-column sortable show-overflow-tooltip prop="billNo" align="center" label="单据号"></el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="orderBillNo"
          align="center"
          label="生产任务号"
          width="120px"
        ></el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="waveCode" align="center" label="波次号"></el-table-column>
<!--        <el-table-column sortable show-overflow-tooltip prop="state" label="状态" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <span v-if="scope.row.state === 1">完成</span>-->
<!--            <span v-if="scope.row.state === -1">撤回</span>-->
<!--          </template>-->
<!--        </el-table-column>-->

        <!--        <el-table-column-->
        <!--          sortable-->
        <!--          show-overflow-tooltip-->
        <!--          prop="reason"-->
        <!--          label="原因"-->
        <!--          align="center"-->
        <!--        >-->
        <!--          <template slot-scope="scope">-->
        <!--            <span v-if="scope.row.reason === null">-</span>-->
        <!--            <span v-else>{{ scope.row.reason }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </el-table>
      <el-pagination
        class="pagination-bottom"
        style="text-align: right"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        :page-sizes="[15, 30, 50, 100]"
        :current-page.sync="searchData.pageNum"
        :page-size="searchData.pageSize"
        layout="sizes, total, prev, pager, next, jumper"
        :total="searchData.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "InventoryTransact",
  data() {
    return {
      isMoreSearch: false,

      searchData: {
        pageNum: 1,
        pageSize: 15,
        total: null,
        keyWords: "",
        wareId: PF.getLocal("wareId", "number"),
        transactType: "",
        itemCode: "",
        itemName: "",
        billType: "",
        detailNo: "",
        state: "",
        reason: "",
        fromBatchName: "",
        fromBoxCode: "",
        fromCellCode: "",
        fromPackDescribe: "",
        fromQuantity: "",
        toBatchName: "",
        toBoxCode: "",
        toCellCode: "",
        toPackDescribe: "",
        toQuantity: "",
        createUserName: "",
        createTimeArr: [],
        startCreateTime: "",
        endCreateTime: "",
        billNo: "",
        waveCode: ""
      },

      inventoryTransacts: [],

      dialogNewVisible: false,
      dialogUpdateVisible: false,

      formLabelWidth: "120px"
    };
  },
  computed: {
    ...mapState(["transactTypes", "billTypes"])
  },
  methods: {
    handleSizeChange(val) {
      this.searchData.pageSize = val;
      this.getInventoryTransactData();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getInventoryTransactData();
    },
    clearSearchData() {
      this.searchData.keyWords = "";
      this.searchData.itemCode = "";
      this.searchData.itemName = "";
      this.searchData.transactType = "";
      this.searchData.buyType = "";
      this.searchData.detailNo = "";
      this.searchData.state = "";
      this.searchData.fromBatchName = "";
      this.searchData.fromBoxCode = "";
      this.searchData.fromCellCode = "";
      this.searchData.fromPackDescribe = "";
      this.searchData.fromQuantity = "";
      this.searchData.toBatchName = "";
      this.searchData.toBoxCode = "";
      this.searchData.toCellCode = "";
      this.searchData.toPackDescribe = "";
      this.searchData.toQuantity = "";
      this.searchData.createUserName = "";
      this.searchData.createTimeArr = [];
      this.searchData.startCreateTime = "";
      this.searchData.endCreateTime = "";
    },
    getInventoryTransactData() {
      let searchData = PF.JSON(this.searchData);
      if (searchData.createTimeArr.length > 0) {
        searchData.startCreateTime = searchData.createTimeArr[0];
        searchData.endCreateTime = searchData.createTimeArr[1];
      }
      IOT.getServerData("/inventory/transacts/list", "get", searchData, ret => {
        if (ret.code === 200) {
          this.inventoryTransacts = ret.rows;
          this.searchData.total = ret.total;
          this.searchData.pageNum = ret.pageNumber;
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    }
  },
  created() {
    // this.getInventoryTransactData();
  },
  mounted() {}
};
</script>

<style scoped lang="less">
.inventoryTransact {
}
</style>
